'''
在一个排序的链表中，存在重复的结点，请删除该链表中重复的结点，重复的结点不保留，返回链表头指针。 例如，链表1->2->3->3->4->4->5 处理后为 1->2->5

解题思路：递归解法判断时候和下一个相等如果相等就一直循环向下不返回值，不等就继续向下递归
'''
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def deleteDuplication1(self, pHead):
        if not pHead:
            return
        if not pHead.next:
            return pHead
        if pHead.next:
            if pHead.val == pHead.next.val:
                while pHead.val == pHead.next.val:
                    pHead = pHead.next
            return self.deleteDuplication(pHead.next)
        else:
            pHead.next = self.deleteDuplication(pHead.next)
            return pHead

    def deleteDuplication(self, pHead):
        if not pHead: return
        if not pHead.next:
            return pHead
        if pHead.val == pHead.next.val:
            if not pHead.next.next: return
            cur = pHead.next.next
            while cur.val == pHead.val:
                cur = cur.next
                if not cur: return
            return self.deleteDuplication(cur)
        else:
            pHead.next = self.deleteDuplication(pHead.next)
            return pHead


a1 = ListNode(1)
a2 = ListNode(1)
a3 = ListNode(1)
a4 = ListNode(1)
a5 = ListNode(1)
a6 = ListNode(1)
a7 = ListNode(1)
a6.next = a7
a5.next = a6
a4.next = a5
a3.next = a4
a2.next = a3
a1.next = a2
s = Solution()
print(s.deleteDuplication1(a1))